package com.dk.service.impl;

import com.dk.VO.TbCarsVO;
import com.dk.mapper.Carsmapper;
import com.dk.pojo.Tbcar;
import com.dk.service.Carservice;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarsServiceimpl implements Carservice {
    @Autowired
    private Carsmapper carsmapper;
    @Override
    public List<Tbcar> getAll() {
        List<Tbcar> tbcars = carsmapper.selectList(null);
        return tbcars;
    }

    @Override
    public TbCarsVO getById(Long id) {
        Tbcar tbcar = carsmapper.selectById(id);
        TbCarsVO tbcarVO = new TbCarsVO();
        BeanUtils.copyProperties(tbcar, tbcarVO);
        return tbcarVO;
    }

    @Override
    public void insert(TbCarsVO car) {
        Tbcar tbcar = new Tbcar();
        BeanUtils.copyProperties(car, tbcar);
        carsmapper.insert(tbcar);
    }

    @Override
    public void deleteById(Long id) {
        carsmapper.deleteById(id);
    }

    @Override
    public void update(TbCarsVO car) {
        Tbcar tbcar = new Tbcar();
        BeanUtils.copyProperties(car, tbcar);
        carsmapper.updateById(tbcar);
    }
}
